#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'LiDong'

import sys


def test():
    args = sys.argv
    if len(args) == 1:
        print('Hello, world!')
    elif len(args) == 2:
        print('Hello, %s!' % args[1])
    else:
        print('Too many arguments!')


if __name__ == '__main__':
    test()


class Animal(object):
    def run(self):
        print('Animal is running...')


class Dog(Animal):
    def run(self):
        print('Dog is running...')

    def eat(self):
        print('Eating meat...')


class Cat(Animal):
    def run(self):
        print('Cat is running...')


dog = Dog()
dog.run()

cat = Cat()
cat.run()

a = list()
b = Animal()
c = Dog()

isinstance(a, list)
isinstance(b, Animal)
isinstance(c, Dog)
isinstance(c, Animal)

b = Animal()
isinstance(b, Dog)
isinstance(b, Animal)


def run_twice(animal):
    animal.run()
    animal.run()


run_twice(Animal())


class Tortoise(Animal):
    def run(self):
        print('Tortoise is running slowly...')


run_twice(Tortoise())
dir(Tortoise())


class MyObject(object):
    def __init__(self):
        self.x = 9

    def power(self):
        return self.x * self.x


obj = MyObject()

print(hasattr(obj, 'x'))
print(obj.x)
print(hasattr(obj, 'y'))
setattr(obj, 'y', 90)
hasattr(obj, 'y')
getattr(obj, 'y')
print(obj.y)
print(getattr(obj, 'z', 404))  # 获取属性'z'，如果不存在，返回默认值404

hasattr(obj, 'power')
hasattr(obj, 'power——77')


class Student(object):

    @property
    def score(self):
        return self._score

    @score.setter
    def score(self, value):
        if not isinstance(value, int):
            raise ValueError('score must be an integer!')
        if value < 0 or value > 100:
            raise ValueError('score must between 0 ~ 100!')

        self._score = value

s = Student()
s.score = 80
s.score
s.score = 9999


class Student(object):

    @property
    def birth(self):
        return self._birth

    @birth.setter
    def birth(self, value):
        self._birth = value

    @property
    def age(self):
        return 2015 - self._birth

